#include "OrderWindow.h"
#include "ui_OrderWindow.h"

OrderWindow::OrderWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::OrderWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("订单详情");
}

OrderWindow::~OrderWindow()
{
    delete ui;
}

//显示OrderWindow
void OrderWindow::init(FoodOrder foodOrder){
    ui->name_label->setText(foodOrder.user_name);
    ui->phone_label->setText(foodOrder.user_phone);
    ui->money_label->setText(QString::number(foodOrder.price));
    ui->id_label->setText(QString::number(foodOrder.id));

    QString temp = foodOrder.bill;
    QString bill = "";
    QString::const_iterator ch = NULL;
    int i = 0;
    //读取账单
    for(ch=temp.cbegin();ch<temp.cend();ch++){
        if((*ch) != "/"){
            bill += (*ch);
        }
        else if((*ch) == "/"){
            if(i%2 == 0){
                bill += "\t";
            }else{
                bill += "元\n";
            }
            i++;
        }
    }
    ui->bill_label->setText(bill);
}

//删除订单
void OrderWindow::on_finish_btn_clicked(){
    FoodOrderTable food_order_table;

    int id = ui->id_label->text().toInt();
    food_order_table.deleteFoodOrder(id);

    emit dataChange();
    this->hide();
}
